#include <bits/stdc++.h>
using namespace std;

template <class Info>
struct SegmentTree {
    int n;
    vector<Info> info;
    SegmentTree() : n(0){}
    SegmentTree(int n_, Info v_ = Info()) {
        init(vector<Info>(n_, v_));
    }
    template<class T> 
    SegmentTree(vector<T> init_) {
        init(init_);
    }
    template<class T>
    void init(vector<T> init_) {
        n = init_.size();
        info.assign(4 << std::__lg(n), Info());
        std::function<void(int, int, int)> build = [&] (int p, int l, int r) {
            if(r - l == 1) {
                info[p] = init_[l];
                return;
            }
            int m = (l + r) / 2;
            build(2 * p, l, m);
            build(2 * p + 1, m, r);
            pull(p);
        };
        build(1, 0, n);
    }
    void pull(int p) {
        info[p] = info[2 * p] + info[2 * p + 1];
    }
    void modify(int p, int l, int r, int x, const Info (v)) {
        if(r - l == 1) {
            info[p] = v;
            return;
        }
        int m = (l + r) / 2;
        if(x < m) {
            modify(2 * p, l, m, x, v);
        }else{
            modify(2 * p + 1, m , r, x, v);
        }
        pull(p);
    }
    void modify(int p, const Info (v)) {
        modify(1, 0, n, p, v);
    }
    Info rangeQuery(int p, int l, int r, int x, int y) {
        if(l >= y || r <= x) {
            return Info();
        }
        if(l >= x && r <= y) {
            return info[p];
        }
        int m = (l + r) / 2;
        return rangeQuery(2 * p, l, m, x, y) + rangeQuery(2 * p + 1, m, r, x, y);
    }
    Info rangeQuery(int l, int r) {
        return rangeQuery(1, 0, n, l, r);
    }
};

struct Info {
    int g = 0;
};

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}

Info operator+(const Info &a, const Info &b) {
    return {gcd(a.g, b.g)};
}

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    SegmentTree<Info> seg(n);
    for(int i = 1; i < n; i++) {
        seg.modify(i, {abs(a[i] - a[i - 1])});
    }
    for(int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        cout << seg.rangeQuery(l, r).g << " \n"[i == q - 1];
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while(t--) solve();
    
    return 0;
}